

package Componentes;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
 * @author Luis Antonio Lara Capetillo
 * Fecha: 09/05/12
 *
 * Descripcion:
 * Clase donde se crea un ventana con una barra
 *
 *
 * @version 1.0
 */
public class C_Ventana extends JFrame{
    private JPanel panel;
    private JButton btn_arriba;
    private JButton btn_abajo;
    private JButton btn_izq;
    private JButton btn_der;
    private int y=0;
    private int x=0;

    public C_Ventana(String titulo){
        super(titulo);
        this.setSize(800,600);
        addComponentes();
        addEventos();
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }

    private void addComponentes() {
        JPanel p_izq= new JPanel();
        JPanel p_der= new JPanel();
        JPanel p_sur= new JPanel();
        JPanel p=new JPanel();
        p.setLayout(new BorderLayout());
        panel= new JPanel();
//        panel.setLayout(null);
        
        for(int i=0;i<30;i++){
            JButton b= new JButton("b"+i);
//            b.setBounds(i, i*40, 80, 35);
            panel.add(b);
        }
        p_izq.setLayout(null);
        panel.setBounds(x, y, 400, 400);
        p_izq.add(panel);

        p_der.setLayout(new BorderLayout());
        btn_arriba= new JButton("Arriba");
        btn_abajo= new JButton("Abajo");
        p_der.add(btn_arriba,"North");
        p_der.add(btn_abajo,"South");

        p_sur.setLayout(new BorderLayout());
        btn_izq= new JButton("Izq");
        btn_der= new JButton("Der");
        p_sur.add(btn_izq,"West");
        p_sur.add(btn_der,"East");

        p.add(p_izq,"Center");
        p.add(p_der,"East");
        p.add(p_sur,"South");

        add(p);
    }

    private void addEventos() {
        btn_arriba.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                panel.setBounds(x, y+=20, panel.getWidth(), panel.getHeight());
            }
        });

        btn_abajo.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                panel.setBounds(x, y-=20, panel.getWidth(), panel.getHeight());
            }
        });

        btn_izq.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                panel.setBounds(x+=20, y, panel.getWidth(), panel.getHeight());
            }
        });

        btn_der.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                panel.setBounds(x-=20, y, panel.getWidth(), panel.getHeight());
            }
        });
    }

    public static void main(String[] args){
        new C_Ventana("Prueba scroll");
    }

}
